package text_2023_09_24;

import java.io.*;

/**
 * @author Vv
 * @version 1.0
 * @project coding_learn
 * @description
 * @date 2023/9/24 22:09:11
 */
public class Demo4 {
    public static void main(String[] args) throws IOException {
        FileReader fr = null;
        BufferedReader br = null;
        FileWriter fw = null;
        BufferedWriter bw = null;
        System.out.println("开始初始化输入输出字符流");
        File inputFile = new File("d:/java24/text01.txt");
        try {
            fr = new FileReader(inputFile);
            br = new BufferedReader(fr);
            fw = new FileWriter("d:/java24/text02.txt",true);
            bw = new BufferedWriter(fw);
            while(true){
                String content = br.readLine();
                if(content != null){
                    System.out.println("读到了一行，开始写入");
                    bw.write(content);
                    bw.newLine();
                }else{
                    System.out.println("拷贝完成");
                    break;
                }
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            bw.close();
            fw.close();
            br.close();
            fr.close();
        }
    }
}
